<?php
/*----------------------------------------------------------------------
 * 公用函数模型管理
 * Author: ming.nie
----------------------------------------------------------------------*/

namespace Admin\Widget;
use Think\Controller;

class AreaWidget extends Controller {
	public function multLevel($is_empty, $id_pre, $type_id, $mutil_level_data_id_1=0, $mutil_level_data_id_2=0, $mutil_level_data_id_3=0){
		$commonLogic = new \Common\Logic\CommonLogic();
		
		$type_id = $type_id;
		$id_pre = "";
		if(isset($data['id_pre']) && !empty($data['id_pre']))
		{
			$id_pre = $data['id_pre'];
		}
		
		$is_detail = 0;
		if(isset($data['is_detail']))
		{
			$is_detail = $data['is_detail'];
		}
		
		//1级部门
		$mutil_level_data_option_1 = $commonLogic->getAreaOptions(array('parentid'=>0));
		if(1 == $is_empty)
		{
			$mutil_level_data_option_1 = array(''=>'')+$mutil_level_data_option_1;
		}
		if(!empty($mutil_level_data_option_1))
		{
			foreach($mutil_level_data_option_1 as $key => $value)
			{
				$current_key_1 = $key;
				if(0 < $mutil_level_data_id_1)
				{
					if($key == $mutil_level_data_id_1)
					{
						break;
					}
				}
				else
				{
					break;
				}
			}
		}
		//2级部门
		if(0 < count($mutil_level_data_option_1) && $current_key_1)
		{
			$mutil_level_data_option_2 = $commonLogic->getAreaOptions(array('parentid'=>$current_key_1));
			foreach($mutil_level_data_option_2 as $key => $value)
			{
				$current_key_2 = $key;
				if(0 < $mutil_level_data_id_2)
				{
					if($key == $mutil_level_data_id_2)
					{
						break;
					}
				}
				else
				{
					break;
				}
			}
		}
		else
		{
			$mutil_level_data_option_2 = array();
		}
		$mutil_level_data_option_2_count = count($mutil_level_data_option_2);
		//3级部门
		if(0 < count($mutil_level_data_option_2) && $current_key_2)
		{
			$mutil_level_data_option_3 = $commonLogic->getAreaOptions(array('parentid'=>$current_key_2));
		}
		else
		{
			$mutil_level_data_option_3 = array();
		}
		$mutil_level_data_option_3_count = count($mutil_level_data_option_3);
		
		$this->assign(get_defined_vars());
        $this->display('Area:multLevel');
	}
}
